﻿using System;
using JRBase;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace JRTestGame
{
    public class Enemy : Actor
    {
        public int Speed { get; private set; }
        private int movement;
        private int initMovement;
        private bool up;

        public void Initialize(Texture2D texture, Rectangle rectangle,
            int frameCount, int speed)
        {
            Speed = speed;
            initMovement = rectangle.Y;
            movement = 200;
            up = true;

            AnimatedSprite sprite = new AnimatedSprite();
            sprite.Initialize(texture, new Vector2(rectangle.X, rectangle.Y), rectangle.Width,
                rectangle.Height, frameCount, 30, Color.White, 1f, true);
            base.Initialize(sprite, rectangle, 15.0f);


        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            sprite.Draw(spriteBatch);
        }

        public override void Update(GameTime gameTime, Vector2 drawPosition)
        {
            if (up)
            {
                if (Y > initMovement - movement)
                {
                    Y -= Speed;
                }
                else
                {
                    up = false;
                }
            }
            else
            {
                if (Y <= initMovement)
                {
                    Y += Speed;
                }
                else
                {
                    up = true;
                }
            }

            sprite.Position = drawPosition;
            sprite.Update(gameTime);
        }
    }
}
